Uec3.DesktopListWindow = Ext.extend(Ext.app.Module, {
			gridStore : null,
			modifyDesktop : function(rowIndex) {
				var record = this.gridStore.getAt(rowIndex);
				var desktop = this.app.getDesktop();
				var detailWindow = new Uec3.DesktopDetailWindow();
				detailWindow.init();
				detailWindow.createWindow(this.app, record);

			},
			modifyMenus : function(rowIndex) {
				var record = this.gridStore.getAt(rowIndex);
				var desktop = this.app.getDesktop();
				var menuWindow = new Uec3.DesktopMenuWindow();
				menuWindow.init();
				menuWindow.createWindow(this.app, record);

			},
			createDesktop : function() {
				var desktop = this.app.getDesktop();
				var detailWindow = new Uec3.DesktopDetailWindow();
				detailWindow.init();
				detailWindow.createWindow(this.app);

			},
			createElements : function() {
				var module = this;
				module.gridStore = new Ext.data.Store({
							proxy : new Ext.data.HttpProxy({
										url : Uec3.App.Constants.homeUrl + "/desktop/list.do"
									}),
							baseParams : {
								start : 0,
								limit : 20
							},
							remoteSort : true,
							reader : new Ext.data.JsonReader({
										totalProperty : 'total',
										root : 'items'
									}, [{
												name : 'id'
											}, {
												name : 'name'
											}, {
												name : 'description'
											}])
						});
				var gridColumnAction = {
					header : "操作",
					width : 150,
					sortable : false,
					dataIndex : 'id',
					renderer : this.moduleActionRenderer([{
								func : "modifyDesktop",
								desc : "编辑基本资料",
								reader : function(value, cellmeta, record, rowIndex, columnIndex, store) {
									return rowIndex;
								}
							}, {
								func : "modifyMenus",
								desc : "编辑菜单",
								reader : function(value, cellmeta, record, rowIndex, columnIndex, store) {
									return rowIndex;
								}
							}])
				};
				var gridColumnModel = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), gridColumnAction, {
							header : '桌面名称',
							width : 200,
							sortable : false,
							dataIndex : 'name'
						}, {
							header : '描述信息',
							width : 659,
							sortable : false,
							dataIndex : 'description'
						}]);
				var gridPanel = new Ext.grid.GridPanel({
							enableColumnMove : false,
							enableColumnMoveResize : false,
							stripeRows : true,
							autoScroll : true,
							width : '100%',
							loadMask : {
								msg : '...加载数据中'
							},
							viewConfig : {
								autoScroll : true,
								columnsText : '显示的列',
								scrollOffset : 20,
								sortAscText : '升序',
								sortDescText : '降序'
							},
							tbar : new Ext.Toolbar(['-', {
										text : '新增桌面类型',
										handler : function() {
											module.createDesktop();
										}
									}]),
							bbar : new Ext.PagingToolbar({
										pageSize : 20,
										store : module.gridStore,
										displayInfo : true,
										displayMsg : '第 {0} - {1} 条  共 {2} 条',
										emptyMsg : '没有记录'
									}),
							iconCls : 'acc-icon',
							// title : '桌面类型列表',
							cm : gridColumnModel,
							store : module.gridStore
						});
				module.gridStore.load();
				return gridPanel;
			},

			init : function(initParams) {
			},

			createWindow : function() {
				var desktop = this.app.getDesktop();
				var win = desktop.getWindow('desktopListWin');
				if (!win) {
					win = desktop.createWindow({
								id : 'desktopListWin',
								title : '桌面类型列表',
								iconCls : 'acc-icon',
								taskbuttonTooltip : '桌面类型列表',
								width : 900,
								height : 500,
								autoScroll : true,
								shim : false,
								animCollapse : false,
								constrainHeader : true,
								maximizable : false,
								resizable : false,
								layout : "fit",
								items : this.createElements()
							});
				}
				win.show();
			}
		});

Uec3.DesktopDetailWindow = Ext.extend(Ext.app.Module, {
			detailFormAjax : null,
			createElements : function(desktopInfo) {

				var detailFormPanel = new Ext.form.FormPanel({
							border : false,
							frame : true,
							height : 220,
							items : [{
										layout : 'form',
										items : [{
													xtype : 'fieldset',
													defaultType : 'textfield',
													border : false,
													items : [{
																name : 'id',
																fieldLabel : 'id',
																xtype : 'hidden'
															}, {
																xtype : 'textfield',
																fieldLabel : '桌面名称',
																name : 'name',
																width : 150,
																anchor : '98%',
																allowBlank : false,
																blankText : "桌面名称不能为空！"
															}]
												}, {
													xtype : 'fieldset',
													border : false,
													items : [{
																name : 'description',
																preventScrollbars : true,
																xtype : 'textarea',
																fieldLabel : '备注',
																anchor : '98%',
																emptyText : ''
															}]
												}]
									}]
						});

				return detailFormPanel;
			},

			init : function(initParams) {
				this.detailFormAjax = new Ext.data.Connection();
				this.detailFormAjax.on('beforerequest', function() {
							Ext.MessageBox.wait("保存数据中...", "提示");
						});

				this.detailFormAjax.on('requestcomplete', function() {
							Ext.MessageBox.hide();
						});

			},

			createWindow : function(app, desktopInfo) {
				var hasData = desktopInfo && desktopInfo.id > 0;
				var winId = "desktop-detail-" + (hasData ? desktopInfo.id : "0");
				var desktop = app.getDesktop();
				var module = this;

				var win = desktop.getWindow(winId);
				if (!win) {
					var detailFormPanel = this.createElements(desktopInfo);
					var titleName = "新增桌面类型-按ESC键退出";
					var tooltip = "新增桌面类型";
					var actionName = "新增";
					var subUrl = "/desktop/add.do";
					if (hasData) {
						// 初始化JsModule
						detailFormPanel.getForm().loadRecord(desktopInfo);
						titleName = "编辑桌面类型-按ESC键退出";
						tooltip = "编辑桌面类型";
						actionName = "编辑";
						subUrl = "/desktop/modify.do";
					}
					win = desktop.createWindow({
								id : winId,
								title : titleName,
								iconCls : 'acc-icon',
								taskbuttonTooltip : tooltip,
								width : 480,
								shim : false,
								animCollapse : false,
								constrainHeader : true,
								maximizable : true,
								maximized : false,
								listeners : {
									'resize' : function(win, width, height) {
										var grid = win.items.get(0);
										var winMinWidth = 400;
										var winMinHeight = 240;
										if (width < winMinWidth || height < winMinHeight) {
											win.setWidth(winMinWidth);
											win.setHeight(winMinHeight);
											grid.setHeight(winMinHeight - 28);
										} else {
											grid.setHeight(height - 28);
										}
									}
								},
								items : detailFormPanel,
								buttons : [{
											text : actionName,
											handler : function() {
												var detailForm = detailFormPanel.getForm();
												if (!detailForm.isValid()) {
													Ext.Msg.alert("提示", "请按要求进行正确操作!");
													return;
												}
												var formValues = detailForm.getValues();

												module.detailFormAjax.request({
															url : Uec3.App.Constants.homeUrl + subUrl,
															success : function(res) {
																var result = Ext.decode(res.responseText);
																if (result && result.id > 0) {
																	detailForm.findField("id").setValue(result.id);
																	Ext.Msg.alert('提示', "操作成功!");
																} else {
																	Ext.Msg.alert("提示", "操作失败!");
																}

															},
															failure : function(res) {
																Ext.Msg.alert('失败', "网络出现异常,请重先连接");
															},
															params : formValues
														});
											}
										}, {
											text : '关闭',
											handler : function() {
												win.close();
											}
										}]
							});
				}
				win.show();
			}
		});

Uec3.DesktopMenuWindow = Ext.extend(Ext.app.Module, {
			menuFormAjax : null,
			createElements : function(desktopInfo) {
				var menuTreePanel = new Ext.tree.TreePanel({
							height : 400,
							width : 440,
							useArrows : true,
							autoScroll : true,
							enableDD : true,
							layout : 'form',
							frame : true,
							root: {
			            id: 0,
			            text: '权限角色',
			            permission:{id:0,isGroup:1},
			            nodeType: 'async'
			        },
							loader : new Ext.tree.TreeLoader({
										dataUrl : Uec3.App.Constants.appUrl + '/desktop/subMenus.do',
									  baseParams : {'desktopId':desktopInfo.id},
									  createNode : function(attr){
									  	return new Ext.tree.TreeNode({'id':attr.id,'text':attr.menuName});
                  	},
										listeners : {
											'loadexception' : function(tl, node, response) {
												Ext.Msg.alert("错误", "加载失败,请重新加载!");
											}
										}
									}),
							tbar : [{
										text : "编辑",
										iconCls : 'icon-edit',
										handler : function() {
											var curNode = tree.getSelectionModel().getSelectedNode();
											if (curNode) {
												form.getForm().reset();
												form.getForm().findField("parentId").setValue(curNode.attributes.permission.id);
												window.show();
											} else {
												Ext.Msg.alert("信息", "请选择一节点");
											}
										}
									}, {
										text : "删除",
										iconCls : 'icon-del',
										handler : function() {
											var curNode = tree.getSelectionModel().getSelectedNode();
											if (curNode) {
												window.show();
												form.getForm().setValues(curNode.attributes.permission);
											} else {
												Ext.Msg.alert("信息", "请选择一节点");
											}
										}
									}, {
										text : "新增子菜单",
										iconCls : 'icon-add',
										handler : function() {
											var curNode = tree.getSelectionModel().getSelectedNode();
											if (curNode) {
												Ext.Msg.confirm("提示:", "确定删除", function(btn) {
															if (btn == 'yes') {
																ajax.request({
																			url : Uec3.App.Constants.homeUrl + '/permission/base!delete.do',
																			params : {
																				id : curNode.attributes.permission.id
																			},
																			success : function(response, options) {
																				var result = Ext.decode(response.responseText);
																				if (result.success = "OK") {
																					curNode.remove(true);
																				}
																			}
																		});
															}
														});
											} else {
												Ext.Msg.alert("信息", "请修改再保存!");
											}
										}
									}],
							listeners : {
								'remove' : function(tree, parent, node) {
									if (!parent.hasChildNodes()) {
										parent.leaf = true;
										parent.select();
									}
								},
								'append' : function(tree, parent, node) {

								},
								'beforemovenode' : function(tree, node, oldParent, newParent, index) {
									Ext.MessageBox.confirm("警告", "确定移动", function(btn) {
												if (btn == 'yes') {
													ajax.request({
																url : Uec3.App.Constants.homeUrl + '/permission/base!updateParent.do',
																params : {
																	id : node.attributes.permission.id,
																	oldParentId : oldParent.attributes.permission.id,
																	newParentId : newParent.attributes.permission.id
																},
																success : function(response, options) {
																	var result = Ext.decode(response.responseText);
																	if (result.success = "OK") {

																	} else {
																		Ext.MessageBox.alert("信息", result.success);
																		tree.getLoader().load();
																	}
																}
															});
												} else {
													return false;
												}
											});
								},
								'movenode' : function(tree, node, oldParent, newParent, index) {

								}
							}
						});
				var menuFormPanel = new Ext.form.FormPanel({
							border : false,
							frame : true,
							height : 420,
							items : [{
										layout : 'form',
										items : [{
													xtype : 'fieldset',
													defaultType : 'textfield',
													border : false,
													items : [{
																name : 'id',
																fieldLabel : 'id',
																xtype : 'hidden'
															}, {
																xtype : 'textfield',
																fieldLabel : '桌面名称',
																name : 'name',
																width : 150,
																anchor : '98%',
																readOnly : true
																,
															}]
												}, {
													xtype : 'fieldset',
													border : false,
													items : [menuTreePanel]
												}]
									}]
						});

				return menuFormPanel;
			},

			init : function(initParams) {
				this.menuFormAjax = new Ext.data.Connection();
				this.menuFormAjax.on('beforerequest', function() {
							Ext.MessageBox.wait("保存数据中...", "提示");
						});

				this.menuFormAjax.on('requestcomplete', function() {
							Ext.MessageBox.hide();
						});

			},

			createWindow : function(app, desktopInfo) {
				var winId = "desktop-menu-" + desktopInfo.id;
				var desktop = app.getDesktop();
				var module = this;
				var win = desktop.getWindow(winId);

				if (!win) {
					var menuFormPanel = this.createElements(desktopInfo);
					menuFormPanel.getForm().loadRecord(desktopInfo);
					win = desktop.createWindow({
								id : winId,
								title : "编辑桌面菜单-按ESC键退出",
								iconCls : 'acc-icon',
								taskbuttonTooltip : "编辑桌面菜单",
								width : 480,
								shim : false,
								animCollapse : false,
								constrainHeader : true,
								maximizable : true,
								maximized : false,
								listeners : {
									'resize' : function(win, width, height) {
										var grid = win.items.get(0);
										var winMinWidth = 400;
										var winMinHeight = 440;
										if (width < winMinWidth || height < winMinHeight) {
											win.setWidth(winMinWidth);
											win.setHeight(winMinHeight);
											grid.setHeight(winMinHeight - 28);
										} else {
											grid.setHeight(height - 28);
										}
									}
								},
								items : menuFormPanel,
								buttons : [{
											text : "编辑",
											handler : function() {
												var menuForm = menuFormPanel.getForm();
												if (!menuForm.isValid()) {
													Ext.Msg.alert("提示", "请按要求进行正确操作!");
													return;
												}
												var formValues = menuForm.getValues();

												module.menuFormAjax.request({
															url : Uec3.App.Constants.homeUrl + "/desktop/modifyMenu.do",
															success : function(res) {
																var result = Ext.decode(res.responseText);
																if (result && result.id > 0) {
																	menuForm.findField("id").setValue(result.id);
																	Ext.Msg.alert('提示', "操作成功!");
																} else {
																	Ext.Msg.alert("提示", "操作失败!");
																}

															},
															failure : function(res) {
																Ext.Msg.alert('失败', "网络出现异常,请重先连接");
															},
															params : formValues
														});
											}
										}, {
											text : '关闭',
											handler : function() {
												win.close();
											}
										}]
							});
				}
				win.show();
			}
		});